export default {
	data () {
		return {
			ajaxloading: false,
		}
	},
	methods: {
		jax (url, data, option = {loading: false, errmsg: '请求发生异常', ldmsg: ''}) {
			option.loading && Indicator.open(option.ldmsg || '');

			return axios({
				url: host + url,
				withCredentials: true,
				data: data,
				method: 'POST'

			}).catch(e => {
				option.loading && Indicator.close();
				this.msg('网络出现异常，请稍后再试');
				console.warn(e);
			})
				.then(res => {
					option.loading && Indicator.close();
					if (res.data.success) {
						return res.data
					} else {
						this.msg(res.data.message);
						return res.data
					}
				})

		},
		get (url, data, option = {errmsg: '请求发生异常'}) {
			this.ajaxloading = true;
			return axios({
				url: host + url,
				withCredentials: true,
				params: data,
				method: 'GET',
                headers: {
                    'Content-Type': 'application/json',
                    'Cache-control': 'no-cache'
                },
			}).catch(e => {
				this.msg('网络出现异常，请稍后再试');
				console.warn(e);
				this.ajaxloading = false;
			})
				.then(res => {
					this.ajaxloading = false;
					if (res.data.success) {
						return res.data
					} else {
						if (!option.slient) {
                            this.msg(res.data.message);
						}
						return res.data
					}

				})

		},
		msg (msg, time = 3) {
			Toast({
				message: msg,
				position: 'bottom',
				duration: time * 1000
			});
		},
		changeTitle (title) {
			document.getElementsByTagName('title')[0].innerHTML = title;
		}
	}
}